<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let str = "jack hello jack";
      console.log(str.replace(/jack/g, "****"));
      // 开始
      console.log(str.replace(/^jack/g, "****"));
      // 结束
      console.log(str.replace(/jack$/g, "****"));
      // 完全匹配
      console.log(str.replace(/^jack$/g, "****"));//jack
    </script>
  </body>
</html>
